import { userType, type Option } from '../../../../../types';
import { IBaseSelector } from '../../../selector/base';
import Role, { type IView } from '../../../selector/role';
import DefaultCcService from '../interpreter/service';

class RoleService extends IBaseSelector implements IView {
  get options(): Option[] {
    return this.panel?.role.options || [];
  }

  component = Role;
  interpreter = new DefaultCcService(userType.role);

  get value(){
    return this.interpreter.value;
  }

  onChange(value: Option[]) {
    this.interpreter.onChange(value);
  }

  initData(): void {
    // 无需初始化
  }

  init() {
    this.interpreter.bindPanelService(this.panel);
    this.interpreter.bindBpmnService(this.root);
    this.interpreter.init();
  }

  onShow() {
    if (this.options.length > 0) return;
    this.initMetaData();
  }

  async initMetaData() {
    await this.panel.role.initData();
  }
}

export default RoleService;
